<!DOCTYPE html>
<html lang="zh-CN" ng-app='he'>
	<head>
		<meta charset='utf-8' />
	
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>剩余假期查询</title>
		
		<script type="text/javascript">
			is_local='{{local}}';
			function loadcss(cssfile) {
		        document.write('\<link rel="stylesheet" href="' + cssfile +'" type="text/css"/\>');
		    }
			function loadjs(script_filename) {
		        document.write('\<script language="javascript" type="text/javascript" src="' + script_filename + '"\>\</script\>');
		    }
		    if(!is_local){
			    static_url='/static';
		    }else{
			    static_url='../../../../static';
		    }
		    // 加载所有微信页面需要的js和css
		    loadjs(static_url+'/js/weixin_page.js')
		</script>
		<script type="text/javascript">
			var app = angular.module('he',['ngSanitize']);
				app.config(function($interpolateProvider) {
				  $interpolateProvider.startSymbol('[[');
				  $interpolateProvider.endSymbol(']]');
				});
			app.controller('content',function ($scope,$http) {
				// 设置body里面的变量
				$scope.name_map={'annual_left':'年假剩余',
								'annual_base':'年假基数',
								'annual_accum':'今年累积年假',
								'annual_left_last':'去年剩余年假',
								'annual_used_this':'今年使用年假',
								'swapoff_left':'剩余调休',
								'swap_expire':'即将过期的调休',
								'day':'天',
								'hour':'小时'
				}
				$scope.leave_order=['annual_left',
									'annual_base',
									'annual_accum',
									'annual_left_last',
									'annual_used_this',
									'swapoff_left']
				if(is_local){
					$scope.leave_data={annual_left:{value:3.4,unit:'day'},
										annual_base:{value:8,unit:'day'},
										annual_accum:{value:0.35,unit:'day'},
										annual_left_last:{value:2.3,unit:'day'},
										annual_used_this:{value:1,unit:'day'},
										swapoff_left:{value:23,unit:'hour'},
										swap_expire:{value:10,unit:'hour'}
							}
					$scope.current_user={cn_name:'何宇林'}
					$scope.leave_history=[
						{id:'1',status:'approved',date:'2016-01-05',category:'annual',span:'2',detail_url:'leave_detail.html?id=fuck'},
						{id:'2',status:'rejected',date:'2016-01-05',category:'annual',span:'2',detail_url:'#'},
						{id:'3',status:'pending',date:'2016-01-05',category:'annual',span:'2',detail_url:'#'},
						{id:'4',status:'revoked',date:'2016-01-05',category:'annual',span:'2',detail_url:'#'},
						{id:'5',status:'checking',date:'2016-01-05',category:'annual',span:'2',detail_url:'#'}]
				}else{
					// 从服务器初始化
					var post_url='/attendance/ajax/';
					$scope.loading=true;
					function init_from_server() {
							var post_data = {
									leave_query:{},
									leave_record_90:{},
									current_user:{}
								};  
							$http.post(post_url,post_data)
							.success(function(data, status, headers, config) { 
								$scope.leave_data=data.leave_query
								$scope.leave_history=data.leave_record_90.leaves
								$scope.current_user=data.current_user
								$scope.loading=false;
							}).error(function(data, status, headers, config) {  
							    //处理错误 
							    $scope.std='有错误,返回码为:'+status;
							});
					}
					init_from_server();
				}
				$scope.redirect=function (url) {
					location=url
				}
			})
		</script>
	</head>
	<body ng-controller='content' ng-show='!loading'>
		<!-----------------在这里填写内容------------------------>
		<div class="container">

	    <div class="row">
			<div class="page-header">
			  	<h1>假期查询
			  		<small>
					  	<span ng-bind='current_user.cn_name'></span>
					 </small>
				</h1>
			</div>
		    
		    <p class="remaining">当前情况</p>
	        <div class="col-xs-12 clear">
		 		<table class="table">
		 			<tr ng-repeat='name in leave_order'>
			 			<td ng-bind='name_map[name]'></td>
			 			<td>
				 			<span ng-bind='leave_data[name].value'></span>
				 			<span ng-bind='name_map[leave_data[name].unit]'></span>
			 			</td>
		 			</tr>
		 		</table>
	        </div>
		    </div>
		<div class="row">
			<p class="remaining">最近90天请假记录</p>

			
		        <div class="li-group col-xs-12" ng-show='leave_history.length==0'>
			        最近90天，没有请假记录
		        </div>
	           
	            	<table class="table">
		            	<tr ng-repeat='leave in leave_history | orderBy:"-id"' 
		            		ng-click='redirect(leave.detail_url)'>
			            	<td>
				            	<span>
				                <span ng-bind='leave.date'></span> ,
				                <span ng-bind='leave.category'></span> ,
			                	<span ng-hide='leave.category=="swap_off"'>
				                	<span ng-bind='leave.span' ></span> 
				                	days
				                </span> 
			                	<span ng-show='leave.category=="swap_off"'>
				                	<span ng-bind='leave.span' ></span> 
				                	hours
				                </span> 
		                	</span>
			            	</td>
			            	<td>
				            	<span class="span2">
		                    	<a  ng-class="{'checking':'checking','approved':'approved','rejected':'rejected','revoked':'revoked','pending':'pending'}[leave.status]" 
		                    		ng-bind='leave.status'>
		                    	</a>
		                </span>
			            	</td>
		            	</tr>
	            		
	            	</table>

		          
      

		</div>
		</div>
		
		<!-----------------弹出框------------------------>
		<div ng-include src='"info_panel.html"'></div>
		
	</body>
</html>